package com.linxz.wandnroid.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.linxz.ui.GuiHelper;
import com.linxz.wandnroid.R;
import com.linxz.wandnroid.enums.GankBeanType;
import com.linxz.wandnroid.pojo.GankMultiBean;

import java.util.List;

/**
 * @author Linxz
 * 创建日期：2020年02月28日 22:40
 * version：v4.5.4
 * 描述：
 */
public class GankListAdapter extends BaseMultiItemQuickAdapter<GankMultiBean, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public GankListAdapter(List<GankMultiBean> data) {
        super(data);
        addItemType(GankBeanType.TEXT.getType(),            R.layout.wandroid_item_gank_text);
        addItemType(GankBeanType.ONE_BIG_IMAGE.getType(),   R.layout.wandroid_item_gank_one_big_image);
        addItemType(GankBeanType.ONE_SMALL_IMAGE.getType(), R.layout.wandroid_item_gank_one_small_image);
        addItemType(GankBeanType.TWO_IMAGE.getType(),       R.layout.wandroid_item_gank_two_image);
        addItemType(GankBeanType.MULTI_IMAGE.getType(),     R.layout.wandroid_item_gank_three_image);
    }

    @Override
    protected void convert(BaseViewHolder helper, GankMultiBean item) {
        helper.setText(R.id.tvDesc,item.getGankBean().getDesc())
                .setText(R.id.tvWho,item.getGankBean().getWho())
                .setText(R.id.tvTime,item.getGankBean().getCreatedAt())
                .setVisible(R.id.divider,helper.getAdapterPosition()!=mData.size()-1);

        GankBeanType TYPE=GankBeanType.TEXT.typeTpEnum(helper.getItemViewType());
        switch (TYPE){
            case ONE_BIG_IMAGE:
                ImageView iv=helper.getView(R.id.iv);
                GuiHelper.loadImageWithCorner(mContext,item.getGankBean().getImages().get(0),iv,5F);
                break;
            case ONE_SMALL_IMAGE:
                ImageView ivSmall=helper.getView(R.id.iv);
                GuiHelper.loadImageWithCorner(mContext,item.getGankBean().getImages().get(0),ivSmall,2F);
                break;
            case TWO_IMAGE:
                ImageView ivOne=helper.getView(R.id.ivOne);
                ImageView ivTwo=helper.getView(R.id.ivTwo);
                GuiHelper.loadImageWithCorner(mContext,
                        item.getGankBean().getImages().get(0),
                        ivOne,
                        5F,
                        true,
                        false,
                        true,
                        false);
                GuiHelper.loadImageWithCorner(mContext,
                        item.getGankBean().getImages().get(1),
                        ivTwo,
                        5F,
                        false,
                        true,
                        false,
                        true);
                break;
            case MULTI_IMAGE:
                ImageView iv_One=helper.getView(R.id.ivOne);
                ImageView iv_Two=helper.getView(R.id.ivTwo);
                ImageView iv_Three=helper.getView(R.id.ivThree);
                GuiHelper.loadImageWithCorner(mContext,
                        item.getGankBean().getImages().get(0),
                        iv_One,
                        5F,
                        true,
                        false,
                        true,
                        false);
                GuiHelper.loadImage(mContext,item.getGankBean().getImages().get(1),iv_Two);
                GuiHelper.loadImageWithCorner(mContext,
                        item.getGankBean().getImages().get(2),
                        iv_Three,
                        5F,
                        false,
                        true,
                        false,
                        true);
                break;
            default:
                break;
        }
    }
}
